package com.riven.bilibilidemo.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.riven.bilibilidemo.R;
import com.riven.bilibilidemo.bean.BangumiBeanTwo;

/**
 * Created by Pooh on 2017/3/11.
 */
public class MyRecyAdapter extends RecyclerView.Adapter<MyRecyAdapter.MyRecyViewHodler>{
    Context context;
    BangumiBeanTwo bangumiBeanTwo;

    public MyRecyAdapter(Context context, BangumiBeanTwo bangumiBeanTwo) {
        this.context = context;
        this.bangumiBeanTwo = bangumiBeanTwo;
    }

    @Override
    public MyRecyViewHodler onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(context).inflate(R.layout.bangumi_recy_two,parent,false);
        MyRecyViewHodler myRecyViewHodler = new MyRecyViewHodler(view);
        return myRecyViewHodler;
    }

    @Override
    public void onBindViewHolder(MyRecyViewHodler holder, int position) {
        Log.i("TAG", "onBindViewHolder: "+bangumiBeanTwo.getResult().get(position).getTitle());
        holder.recy_up.setText(bangumiBeanTwo.getResult().get(position).getTitle());
        holder.recy_down.setText(bangumiBeanTwo.getResult().get(position).getDesc());
        ImageLoader.getInstance().displayImage(bangumiBeanTwo.getResult().get(position).getCover(),holder.recy_img);
    }

    @Override
    public int getItemCount() {
        return bangumiBeanTwo.getResult().size();
    }

    public class MyRecyViewHodler extends RecyclerView.ViewHolder {

        private final TextView recy_down;
        private final TextView recy_up;
        private final ImageView recy_img;

        public MyRecyViewHodler(View itemView) {
            super(itemView);
            recy_img = (ImageView) itemView.findViewById(R.id.recy_img);
            recy_up = (TextView) itemView.findViewById(R.id.recy_up);
            recy_down = (TextView) itemView.findViewById(R.id.recy_down);
        }
    }
}
